<template>
	<view class="container">
		<view class="nav-container">
			<uni-nav-bar :fixed="false" title="爱芯房" color="#333333" background-color="#FFFFFF" right-icon="server-man"
				@clickLeft="showBuilding()" @clickRight="intoService()">
				<block slot="left">
					<view class="building">
						<text class="nav-title">{{ building }}</text>
						<u-icon name="arrow-down"></u-icon>
					</view>
				</block>
			</uni-nav-bar>
			<u-picker :show="show" @close="()=>show=false" @cancel="()=>show=false" :columns="columns"
				@confirm="confirm" title="选择项目" keyName="floorName"></u-picker>
		</view>
		<view class="content">
			<!-- 正文内容 -->
			<image src="/static/home_icons/public.png" class="image" @click="
          goto('/pages/ihome/public_building/public_building?title=公建芯造')
        "></image>
			<image src="/static/home_icons/house.png" class="image"
				@click="goto('/pages/ihome/house_building/house_building?title=房屋芯造')"></image>
			<image src="/static/home_icons/bignew.png" class="image"
				@click="goto('/pages/ihome/project_memorabilia/project_memorabilia')"></image>
			<image src="/static/home_icons/node.png" class="image"
				@click="goto('/pages/ihome/housing_node/housing_node?title=房屋节点')">
			</image>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				columns: [],
				building: '请选择',
				// userId: '',
			};
		},
		onLoad() {
			uni.setStorageSync('selectedProject', '请选择')
			this.getEstate()
		},
		onShow() {
			console.log('home')
			this.building = uni.getStorageSync('selectedProject')
		},
		methods: {
			//获取绑定的楼盘信息
			async getEstate() {
				const {
					body
				} = await uni.$H.post('/userEstateMap/getByQuery', {
					estateType: '2',
					roleId: "4",
					userId: uni.getStorageSync('userId')
				}, {
					authCode: true
				})
				console.log(body)
				if (body.length != 0) {
					let _t = []
					for (let i = 0; i < body.length; i++) {
						_t.push(body[i].businessRealEstateVO)
					}
					this.columns = [_t]
				}
			},
			confirm(e) {
				console.log('confirm', e);
				this.building = e.value[0].floorName
				uni.setStorageSync('selectedProject', this.building)
				uni.setStorageSync("estateId", e.value[0].floorId)
				this.show = false
			},
			intoService() {
				uni.navigateTo({
					url: '/pages/imine/mine_service/mine_service'
				})
			},
			showBuilding() {
				this.show = true
				this.getEstate()
			},
			goto(url) {
				console.log(uni.getStorageSync("selectedProject"))
				if (typeof uni.getStorageSync("selectedProject") == undefined || uni.getStorageSync("selectedProject") ==
					"请选择" || uni.getStorageSync("selectedProject") == null) {
					uni.$showMsg("请先选择项目");
					return
				} else {
					uni.navigateTo({
						url: url,
					});
				}
			},
		},
	};
</script>

<style lang="scss" scoped>
	.content {
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		justify-content: space-between;
		padding: 30rpx;

		.image {
			width: 335rpx;
			height: 240rpx;
			box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(230, 33, 41, 0.31);
			border-radius: 20rpx;
			margin-bottom: 20rpx;
		}
	}

	.building {
		font-size: 28rpx;
		display: inline-flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-start;
		margin-left: 20rpx;

		.nav-title {
			width: 100rpx;
			overflow: hidden;
			/* #ifndef APP-NVUE */
			white-space: nowrap;
			text-overflow: ellipsis;
			/* #endif */
			/* #ifdef APP-NVUE */
			lines: 1;
			text-overflow: ellipsis;
			/* #endif */
		}
	}

	.nav-container /deep/ .uni-nav-bar-text {
		font-size: 36rpx;
	}
</style>
